package com.example.demo.util;

import com.example.demo.domain.Doc;

import java.util.ArrayList;
import java.util.List;

public class FormatterDoc {
    private List<Doc> arr;

    public FormatterDoc(List<Doc> categoryList) {
        this.arr = categoryList;
    }

    public List<Doc> findDoc(Long parent){
        List<Doc> resDoc = new ArrayList<>();
        for(Doc cat : this.arr){
            if(cat.getParent().equals(parent)){
                resDoc.add(cat);
                cat.setChildren(this.findDoc(cat.getId()));
            }
        }
        return resDoc;
    }

    public String formattrDocName(Long id){
        String name = "";
        for(Doc cat : this.arr){
            if(cat.getId().equals(id)){
                name=cat.getName();
            }
        }
        return name;
    }
}
